/*
web3.eth.sendRawTransaction

web3.eth.call

npm install --save web3
npm install --save ethereumjs-tx
npm install --save web3-eth-abi

npm install -g cnpm -registry=https://registry.npm.taobao.org
cnpm install --save ethereumjs-tx
cnpm install --save web3-eth-abi

 */
var express = require('express');
var router = express.Router();
var Database = require('./database');
var db = new Database();

router.get('/addNote',function(req,res,next){
  var code = global.etherData.addNote(req.query.id,req.query.name,req.query.content);
  req.query['code'] = code;
  db.addNote(req,res);
})
router.get('/updateNote', function(req,res,next){
  req.query['code'] = global.etherData.updateNote(req.query.id,req.query.name,req.query.content);
  db.updateNote(req,res);
})
router.get('/getNote',function(req,res,next){
  res.send({content:global.etherData.getNote(req.query.id,req.query.name)});
})
router.get('/getList',function (req,res,next) {
    db.getNoteList(req,res);
})
router.get('/status', function(req,res,next){
  var result = global.etherData.queryTransactionStatus(req.query.hash);
  if(result == null)
  {
    // 正在等待矿工挖矿
    res.send({info:2});
  }
  else if(result == 1)
  {
    // 交易成功
    res.send({info:1});
  }
  else
  {
    //  交易失败
    res.send({info:0});
  }

})
/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

module.exports = router;
